package com.guonl.plus.controller;

import com.guonl.plus.vo.UserJoinVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.guonl.plus.service.IUserPlusService;
import com.guonl.plus.entity.UserPlus;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author guonl
 * @since 2024-02-05
 */
@RestController
@RequestMapping("/user-plus")
public class UserPlusController {


    @Autowired
    private IUserPlusService iUserPlusService;

    @GetMapping(value = "/list")
    public ResponseEntity<Page<UserPlus>> list(@RequestParam(required = false) Integer current, @RequestParam(required = false) Integer pageSize) {
        if (current == null) {
            current = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        Page<UserPlus> aPage = iUserPlusService.page(new Page<>(current, pageSize));
        return new ResponseEntity<>(aPage, HttpStatus.OK);
    }

    @GetMapping(value = "/id")
    public ResponseEntity<UserPlus> getById(String id) {
        return new ResponseEntity<>(iUserPlusService.getById(id), HttpStatus.OK);
    }

    @PostMapping(value = "/create")
    public ResponseEntity<Object> create(@RequestBody UserPlus params) {
        iUserPlusService.save(params);
        return new ResponseEntity<>("created successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/delete/{id}")
    public ResponseEntity<Object> delete(@PathVariable("id") String id) {
        iUserPlusService.removeById(id);
        return new ResponseEntity<>("deleted successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/update")
    public ResponseEntity<Object> update(@RequestBody UserPlus params) {
        iUserPlusService.updateById(params);
        return new ResponseEntity<>("updated successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/update2")
    public ResponseEntity<Object> update2(@RequestBody UserPlus params) {
        iUserPlusService.updateById2(params);
        return new ResponseEntity<>("updated successfully", HttpStatus.OK);
    }

    @GetMapping(value = "/userId")
    public ResponseEntity<UserPlus> getByUserId(String userId) {
        return new ResponseEntity<>(iUserPlusService.getByUserId(userId), HttpStatus.OK);
    }

    @GetMapping(value = "/userId2")
    public ResponseEntity<UserPlus> getByUserId2(String userId) {
        return new ResponseEntity<>(iUserPlusService.getByUserId2(userId), HttpStatus.OK);
    }

    @GetMapping(value = "/all")
    public ResponseEntity<List<UserPlus>> getByUserAll() {
        return new ResponseEntity<>(iUserPlusService.userAll(), HttpStatus.OK);
    }

    @GetMapping(value = "/getJoinData")
    public ResponseEntity<List<UserJoinVO>> getJoinData(String userId) {
        return new ResponseEntity<>(iUserPlusService.getJoinData(userId), HttpStatus.OK);
    }

    @GetMapping(value = "/getTmpdir")
    public ResponseEntity<String> getTmpdir() {
        String tmpdir = System.getProperty("java.io.tmpdir");
        return new ResponseEntity<>(tmpdir, HttpStatus.OK);
    }


}
